<template>
  <a-button
    type="text"
    style="padding: 5px 12px; height: auto; text-align: left"
    @click="shareClick"
    block
  >
    分享
  </a-button>
</template>
<script setup>
import { message } from 'ant-design-vue'
import useClipboard from 'vue-clipboard3'
import { useDbType } from '@/views/db-management/provide-context.js'
const { toClipboard } = useClipboard()
/**
 * 外部参数
 */
let props = defineProps({
  data: {
    type: Object,
    required: true,
  },
})
let dbType = useDbType()
/**
 * 操作
 */

async function shareClick() {
  try {
    // todo use props.data.fileCode
    // await navigator.clipboard.writeText(props.data.fileCode)
    // await toClipboard(props.data.fileCode)
    let fileInfo =
      window.location.origin +
      window.location.pathname +
      window.location.search +
      (dbType
        ? `#/private/db-management/${dbType}`
        : '#/private/db-management/project') +
      `?dataname=${props.data.dataName}&categoryid=${props.data.parentId}`

    await toClipboard(fileInfo)
    message.success('分享已复制到剪贴板。')
  } catch (e) {
    console.log(e)
    message.warning('分享失败，请重新操作。')
  }
}
</script>
<style lang="less" scoped></style>
